import {BaseUrl} from "../constant/constant";
import {ApiFetch} from "../api/apiHandler";

class AdModel {
    constructor() {
        this.url = BaseUrl
    }

    all = (params) => {
        let end = this.url + 'getguanggao'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    add = (params) => {
        let end = this.url + 'addguanggao'
        let fm = new FormData()
        Object.entries(params).map(([key, value]) => {
            if (value !== undefined && value !== null) {
                if (key === 'photo') {
                    fm.append('photo', value.originFileObj)
                    // fm.append('image', JSON.stringify(imgs))
                } else {
                    fm.append(key, value)
                }
            }

        })
        let req = new ApiFetch(end)
        return req.fetch(fm)
    }

    delete = (params) => {
        let end = this.url + 'delguanggao'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    set = (params) => {
        let end = this.url + 'setguanggao'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }
}

export default AdModel